package org.example.web.configurer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CustomerHandlerExceptionResolver implements HandlerExceptionResolver {
    Logger logger = LoggerFactory.getLogger(CustomerHandlerExceptionResolver.class);

    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        final String msg = e.getMessage() == null ? e.getClass().getName() : (e.getClass().getName() + e.getMessage());
        logger.error(msg, e);
        ModelAndView mav = new ModelAndView();
        mav.addObject("content", msg);
        mav.setView(new PlainHtmlView());
        return mav;
    }
}
